package cz.khfotbal.beans;

import java.util.List;

import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cz.khfotbal.domain.Article;
import cz.khfotbal.domain.Contact;
import cz.khfotbal.service.ContactService;

@Component
@Scope(value = "session")
public class ContactBean {
	
	@Autowired
	private ContactService contactService;
	
	private Contact newContact;
	private Contact selectedContact;
	
	private int idContact;
	
	public ContactBean(){
		newContact = new Contact();
	}
	
	public List<Contact> getContactListKfs(){
		return contactService.getAllContacts("kfs");
	}
	
	public List<Contact> getContactListDalsi(){
		return contactService.getAllContacts("dalsi");
	}
	
	public List<Contact> getContactListVybor(){
		return contactService.getAllContacts("vybor");
	}
	
	public List<Contact> getContactListRozhodci(){
		return contactService.getAllContacts("rozhodci");
	}
	
	public List<Contact> getContactListDelegat(){
		return contactService.getAllContacts("delegat");
	}
	
	public void updateContact(){
		if (selectedContact != null){
			contactService.updateContact(selectedContact);
		}
	}
	
	public void deleteContact(){
		if (selectedContact != null){
			contactService.deleteContact(selectedContact);
		}
	}
	
	public void createContactKfs(){
		newContact.setCategory("kfs");
		contactService.createContact(newContact);
		newContact = new Contact();
	}
	
	public void createContactDalsi(){
		newContact.setCategory("dalsi");
		contactService.createContact(newContact);
		newContact = new Contact();
	}
	
	public void createContactVybor(){
		newContact.setCategory("vybor");
		contactService.createContact(newContact);
		newContact = new Contact();
	}
	
	public void createContactRozhodci(){
		newContact.setCategory("rozhodci");
		contactService.createContact(newContact);
		newContact = new Contact();
	}
	
	public void createContactDelegat(){
		newContact.setCategory("delegat");
		contactService.createContact(newContact);
		newContact = new Contact();
	}
	
	public void setNewContact(Contact newContact){
		this.newContact = newContact;
	}
	
	public Contact getNewContact(){
		return newContact;
	}

	public Contact getSelectedContact() {
		return selectedContact;
	}

	public void setSelectedContact(Contact selectedContact) {
		this.selectedContact = selectedContact;
	}
	
	public Contact getContactById() {
		String parameter = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get( "id" );
		int id = Integer.parseInt(parameter);
		return contactService.getContactById(id);
	}

	public int getIdContact() {
		return idContact;
	}

	public void setIdContact(int idContact) {
		this.idContact = idContact;
	}
	
	

}
